import * as events from './events'
import axios from 'axios'
export const getUserInfo = (context) => {
  return new Promise((resolve, reject) => {
    axios.get('/sys/user/info?num=' + Math.random()).then((data) => {
      resolve(data)
      if (data.data.httpCode === 200) {
        context.commit(events.CHANGE_USER_INFO, data.data.data)
      } else {
        context.commit(events.USER_NOT_LOGIN, data.data.httpCode)
      }
    }).catch((err) => {
      console.log(err)
      reject(err)
    })
  })
}
export const getUserMenus = (context, roleId) => {
  return new Promise((resolve, reject) => {
    axios.get('/sys/role/menu/auth/list?num=' + Math.random(), {
      params: {
        roleId: roleId
      }
    }).then((data) => {
      resolve(data)
      if (data.data.httpCode === 200) {
        context.commit(events.USER_LOGIN_MENUS, data.data.data)
      } else {

      }
    }).catch((err) => {
      console.log(err)
      reject(err)
    })
  })
}
export const getLoginOut = (context) => {
  return new Promise((resolve) => {
    axios.post('/sys/user/logout').then((data) => {
      resolve(data)
      if (data.data.httpCode === 200) {
        context.commit(events.USER_LOGIN_OUT, data.data.data)
      } else {

      }
    }).catch((err) => {
      console.log(err)
    })
  })
}
